import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";
import { unref } from 'vue';
import { router } from '/@/router';
const { createConfirm } = useMessage();

enum Api {
  list = '/crm/workOrder/list',
  save='/crm/workOrder/add',
  edit='/crm/workOrder/edit',
  deleteOne = '/crm/workOrder/delete',
  deleteBatch = '/crm/workOrder/deleteBatch',
  importExcel = '/crm/workOrder/importExcel',
  exportXls = '/crm/workOrder/exportXls',
  maintainOrdersList = '/crm/workOrder/queryMaintainOrdersByMainId',
  installationOrderList = '/crm/workOrder/queryInstallationOrderByMainId',
  workOrderProcessList = '/crm/workOrder/queryWorkOrderProcessByMainId',
  receivingOrders='/crm/workOrder/receivingOrders',
  statistics = '/crm/workOrder/statistics',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 子表单查询接口
 * @param params
 */
export const queryMaintainOrders = Api.maintainOrdersList
/**
 * 子表单查询接口
 * @param params
 */
export const queryInstallationOrder = Api.installationOrderList
/**
 * 子表单查询接口
 * @param params
 */
export const queryWorkOrderProcess = Api.workOrderProcessList
/**
 * 列表接口
 * @param params
 */
export const list = (params) => {
  const status = unref(router.currentRoute).query.status;
  console.log("---------------------",unref(router.currentRoute))
  params.workOrderStatus=15;
  return defHttp.get({url: Api.list, params});
}
// export const queryStatistics = Api.statistics

export const queryStatistics = (params) =>
    defHttp.get({url: Api.statistics,params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
/**
 * 子表列表接口
 * @param params
 */
export const maintainOrdersList = (params) =>
  defHttp.get({url: Api.maintainOrdersList, params},{isTransformResponse:false});
/**
 * 子表列表接口
 * @param params
 */
export const installationOrderList = (params) =>
  defHttp.get({url: Api.installationOrderList, params},{isTransformResponse:false});  
/**
 * 子表列表接口
 * @param params
 */
export const workOrderProcessList = (params) =>
  defHttp.get({url: Api.workOrderProcessList, params},{isTransformResponse:false});
  
/**
 * 确认接单
 */
export const takingOrders = (params,handleSuccess) => {
  return defHttp.post({url: Api.receivingOrders, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
